package cn.easybuy.servlet.product;

import cn.easybuy.entity.PageInfo;
import cn.easybuy.entity.Product;
import cn.easybuy.entity.ProductCategory;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/productAllServlet")
public class ProductListServlet extends HttpServlet {
    private ProductService productService = new ProductServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
//            List<Product> productList = productService.getProListAll();
//            req.setAttribute("productList",productList);
//            req.getRequestDispatcher("backend/product/productList.jsp").forward(req,resp);
            int pageNo = Integer.parseInt(req.getParameter("pageNo"));
            PageInfo<Product> page = new PageInfo<>(pageNo,10);
            page = productService.getProListAll(page);
            req.setAttribute("page",page);
            req.getRequestDispatcher("backend/product/productList.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
